package com.ccrfid.rmc6.resource.export;

import com.ccrfid.rmc6.entity.business.entrance.PersonnelAttendanceRecordEntity;
import com.ccrfid.rmc6.pojo.dto.report.*;
import com.ccrfid.rmc6.service.alarm.AlarmRecordService;
import com.ccrfid.rmc6.service.personnel.PersonnelService;
import com.ccrfid.rmc6.service.report.ReportService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.core.io.Resource;
import org.springframework.http.HttpHeaders;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.ws.rs.*;
import javax.ws.rs.core.Context;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.SecurityContext;
import java.io.IOException;
import java.nio.charset.StandardCharsets;
import java.sql.Timestamp;
import java.util.List;


@Path("export")
@Produces(MediaType.APPLICATION_JSON)
public class DataExportResource {
    @Autowired
    private AlarmRecordService alarmRecordService;
    @Autowired
    private PersonnelService personnelService;
    @Autowired
    private ReportService reportService;

//    @GetMapping(value = "/export/alarmRecord")
//    public ResponseEntity<Resource> exportRecord(Long personnelId) throws IOException {
//        String fileName = "告警记录_" + personnelId + ".xls";
//        fileName = new String(fileName.getBytes(), StandardCharsets.ISO_8859_1);
//        Resource file = alarmRecordService.exportAlarmRecord(personnelId);
//        return ResponseEntity.ok()
//                .header(HttpHeaders.CONTENT_DISPOSITION, "attachment; filename=" + fileName)
//                .contentType(org.springframework.http.MediaType.parseMediaType("application/vnd.ms-excel"))
//                .body(file);
//    }

    //区域人员统计报表
    @GET
    @Path("locationPerson")
    public List<LocationPersonDto> exportLocationPerson(){
        return reportService.exportLocationReport();
    }

    //获取所有区域类型下的区域
    @GET
    @Path("get-allLocation")
    public List<LocationInfoDto> getAllLocator(){
        return reportService.getAllLocation();

    }

    //按区域id获取告警统计
    @GET
    @Path("locationAlarm")
    public LocationAlarmDto exportLocationAlarm(@QueryParam("locationId") Long locationId,
                                                      @QueryParam("startTime")Timestamp startTime,
                                                      @QueryParam("endTime") Timestamp endTime){
        return reportService.exportLocationAlarmReport(locationId, startTime, endTime);
    }


    //区域设备统计报表
    @GET
    @Path("locationDevice")
    public List<LocationDeviceDto> exportLocationDevice(){
        return reportService.exportLocationDevice();
    }

    //人员动态分析报表
    @GET
    @Path("personnelAnalyze")
    public PersonnelMoveAnalyzeDto exportPersonnelMoveAnalyze(@QueryParam("personnelId") Long personnelId,
                                                              @QueryParam("startTime")Timestamp startTime,
                                                              @QueryParam("endTime") Timestamp endTime){
        return reportService.exportPersonnelMoveAnalyze(personnelId, startTime, endTime);
    }

    //考勤统计报表
    @GET
    @Path("personnelEntrance")
    public List<PersonnelAttendanceRecordEntity> exportPersonnelEntrance(@QueryParam("personnelId") Long personnelId,
                                                                         @QueryParam("startTime")Timestamp startTime,
                                                                         @QueryParam("endTime") Timestamp endTime){

        return reportService.exportPersonnelAttendance(personnelId, startTime, endTime);
    }

}
